package com.example.wechat.login.dto;

import com.example.wechat.login.entity.WechatUser;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.experimental.Accessors;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Accessors(chain = true)
public class WechatLoginResponse {
    private String token;
    private UserInfo userInfo;

    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    @Builder
    @Accessors(chain = true)
    public static class UserInfo {
        private Long id;
        private String openid;
        private String nickname;
        private String avatarUrl;
        private Integer gender;
        private String country;
        private String province;
        private String city;
        private String language;
        private String phoneNumber;

        public static UserInfo fromEntity(WechatUser user) {
            return user == null ? null : builder()
                .id(user.getId())
                .openid(user.getOpenid())
                .nickname(user.getNickname())
                .avatarUrl(user.getAvatarUrl())
                .gender(user.getGender())
                .country(user.getCountry())
                .province(user.getProvince())
                .city(user.getCity())
                .language(user.getLanguage())
                .phoneNumber(user.getPhoneNumber())
                .build();
        }
    }
}
